package com.yoo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.yoo.entity.Article;
import com.yoo.entity.Author;
import com.yoo.entity.Contact;
import com.yoo.service.ArticleService;
import com.yoo.service.AuthorService;
import com.yoo.service.ContactService;

@Controller
@RequestMapping("/article")
public class ArticleController {

	@Autowired
	private ArticleService articleService;
	@Autowired
	private ContactService contactService;
	@Autowired
	private AuthorService authorService;

	@RequestMapping("/{articleId}/detail")
	public String detail(@PathVariable("articleId") Long articleId, Model model) {
		Article article = articleService.selectById(articleId);
		Author author = authorService.selectById(article.getAuthorId());
		model.addAttribute("article", article);
		model.addAttribute("author", author);
		List<Contact> list = contactService.queryByAuthorId(article.getAuthorId());
		model.addAttribute("contactList", list);
		return "article";

	}

	@RequestMapping("/index")
	public String index() {
		return "index";
	}
}
